...

View Full Version : A few mysql errors I need help with



j634
10-23-2009, 10:56 AM
Hi all,

I am getting these errors on my script and can't seem to find a solution.



Warning: mysql_numrows() expects parameter 1 to be resource, string given in C:\wamp\www\mysite\lib\mysql.lib on line 23

Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\wamp\www\mysite\lib\mysql.lib on line 29


Here is the php code:



function c(){
global $db_host, $db_login, $db_pswd;
$db = "mysql_connect($db_host,$db_login,$db_pswd)";
return $db;
}

function q($q_str){
global $db_name;
$r = "mysql_query($db_name,$q_str)";
return $r;
}

function d($db){
// mysql_close($db);
}

function e($r)
{
if(mysql_numrows($r))
return 0;
else return 1;
}

function f($r){
return mysql_fetch_array ($r);
}

function nr($r){
return mysql_num_rows($r);
}


The first error is on line 23 which is this code:



function e($r)
{
if(mysql_numrows($r))
return 0;
else return 1;
}


The second error is on line 29 which is this code:



function f($r){
return mysql_fetch_array ($r);
}


Errors are highlighted in red.

Thanks for any help.

SystemJay
10-23-2009, 11:52 AM
I belive that you are trying to use strings:

$db = "mysql_connect($db_host,$db_login,$db_pswd)";
$r = "mysql_query($db_name,$q_str)";

Those above are strings, ie $hello="Hello World";


$db = mysql_connect($db_host,$db_login,$db_pswd);
$r = mysql_query($db_name,$q_str);

Remove quotes and you will get "resources". :)
Thats what I came up with first glance of the code.

karlosio
10-23-2009, 04:31 PM
You are creating functions out of functions.. are more simpler way would be

<?php
$server = 'server'; // localhost or whatever
$user = 'dbusername';
$password = 'dbpassword';
$db = 'database';

$conn = mysql_connect($server, $user, $password) or die("Cannot connect to server ".mysql_error());
mysql_select_db($db, $conn) or die("Cannot find database " . mysql_error());

$query = "SELECT column FROM table";
$result = mysql_query($query, $conn) or die("Error in query: ".mysql_error());
$rows = mysql_num_rows($result);
$row = mysql_fetch_assoc($result); // or $row = mysql_fetch_array($result)

j634
10-26-2009, 02:13 PM
Thanks guys will give it a try. Sorry for the late reply have had internet malfunctions.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum