Re: PHP-MySQL connection for particular module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> [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/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux