IT Community - Software Programming, Web Development and Technical Support

PHP with Mysql examples

This is a discussion on PHP with Mysql examples within the PHP Programming forums, part of the Web Development category; MySql Connection with PHP example <?php $host="MySql Host Address"; $username="localhost"; $password="password&...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  3 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 11-19-2007, 06:02 AM
varghese varghese is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 93
varghese is on a distinguished road
Thumbs up PHP with Mysql examples

MySql Connection with PHP example

<?php
$host="MySql Host Address";
$username="localhost";
$password="password";

$connection= mysql_connect ($host, $username, $password);
if (! $connection) {
die ("A connection to the Server could not be established!");
} else {
echo "User root logged into to MySQL server ",$host," successfully.";
}
?>

Thanks
T.Varghese
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-19-2007, 06:46 AM
varghese varghese is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 93
varghese is on a distinguished road
Thumbs up Re: PHP with Mysql examples

Use mysql_result function to get query result

<?php

mysql_connect($host,$username,$password);
mysql_select_db("DBNAME");


$query = "SELECT id, firstname FROM Employee";
$result = mysql_query($query);

$id = mysql_result($result, 0, "id");
$name = mysql_result($result, 0, "firstname");
echo "The first returned id is $id and the name is $name";
?>

Thanks
T.Varghese
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-19-2007, 07:13 AM
Naseema Naseema is offline
D-Web Trainee
 
Join Date: Mar 2007
Posts: 12
Naseema is on a distinguished road
Default Re: PHP with Mysql examples

mysql_ping()
$conn = mysql_connect('localhost', 'root', '');
$db = mysql_select_db('test');

/* Assuming this query will take a long time */
$sql = "select userid from google;
$result = mysql_query($sql);
if (!$result) {
echo 'Query #1 failed, exiting.';
exit;
}

/* Make sure the connection is still alive, if not, try to reconnect */
if (!mysql_ping($conn)) {
echo 'Lost connection, exiting after query #1';
exit;
}
mysql_free_result($result);

/* So the connection is still alive, let's run another query */
$result2 = mysql_query($sql2);
__________________
Nasee
True Faith never Fails
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/php-programming/4538-php-mysql-examples.html
Posted By For Type Date
Return SQL results as PHP variables - WebDeveloper.com This thread Refback 11-27-2007 03:37 AM
Return SQL results as PHP variables - WebDeveloper.com This thread Refback 11-19-2007 07:19 AM
Return SQL results as PHP variables - WebDeveloper.com This thread Refback 11-19-2007 06:52 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP functions and examples varghese PHP Programming 7 11-19-2007 07:02 AM
Create a php function examples varghese PHP Programming 0 11-19-2007 07:00 AM
Form Examples in PHP varghese PHP Programming 6 11-14-2007 10:19 PM
HTML and CSS examples varghese HTML, CSS and Javascript Coding Techniques 0 11-09-2007 04:33 AM
Examples in SQL/MYSQL varghese Database Support 0 11-09-2007 04:10 AM


All times are GMT -7. The time now is 06:28 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0