Re: PHP-MySQL connection for particular module

From: Date: Thu, 19 Jun 2008 23:57:14 +0000
Subject: Re: PHP-MySQL connection for particular module
References: 1 2 3 4 5 6 7  Groups: php.db 
Request: Send a blank email to php-db+get-45094@lists.php.net to get a copy of this message
> [new code] > if (!mysql_connect($a, $b, $c)) return; > > if (!mysql_select_db($dbname)) return; > > $res = mysql_query("SELECT * FROM manual;", $link); > [/new code] Isn't going to work because $link is not defined and definitely not a resource like mysql_query expects. > OR, optionally, to surpress the warnings: > > [new code] > if (!mysql_connect($a, $b, $c)) return; > > $link = null; > > if (!mysql_select_db($dbname)) return; > > $res = mysql_query("SELECT * FROM manual;", $link); > [/new code] Isn't going to work because mysql_query needs a resource to connect to. You've defined $link as null. $ cat test.php <?php $user = 'my_db_user'; $pass = 'my_pass'; $host = 'localhost'; $db = 'my_db'; error_reporting(E_ALL); ini_set('display_errors', true); if (!mysql_connect($host, $user, $pass)) { die("unable to connect"); } if (!mysql_select_db($db)) { die("unable to choose db"); } $link = null; $res = mysql_query('select version() as version', $link); while ($row = mysql_fetch_assoc($res)) { print_r($row); } $ php test.php Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /path/to/test.php on line 19 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /path/to/test.php on line 20 -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.db (#45094) next »