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&...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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 |
| Sponsored Links |
| |||
| 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 |
| |||
| 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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |