Re: [PHP-DB] PHP-MySQL connection for particular module

[email protected] (Chris)
Newsgroups php.db
Message-ID <[email protected]>
> [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/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.