Hey everyone, I'm utilizing a few PHP functions I made and for some reason, I keep getting errors in the queries. In particular this error:
expects parameter 1 to be resource, boolean given on line 66
I'm struggling and I can't seem to find an answer. With that said I'm hoping to find some help here .
SQL Lib
<?PHP
/*
SQL LIB
*/
/*
FUNCTION Guide:
S_ERROR({INT}) <- Gives an error for the {INT} value
S_FILTER({QUERY}) <- Filters {QUERY} Preventing SQL Injections
S_CONNECT({H},{B},{U},{P}) <- Connects to the SQL database
S_OBJECT({QUERY}, {TABLE}) <- Runs the {QUERY} and returns the value of {TABLE}
S_QUERY({QUERY}) <- Executes and filters QUERY
S_ARRAY({QUERY}) <- Returns an array from a query
S_INSERT({B},{H},{A1},{A2}) <- Formats insert queries with {A1} & {A2} as arrays
*/
FUNCTION s_error($_int)
{
$error = array( "[SQL] Connection Error",
"[SQL] Database Select Error",
"[SQL] Error in SQL string (<i>we filter</i>)");
return $error[$_int];
}
FUNCTION s_filter($_q)
{
return $_q = stripslashes(mysql_real_escape_string($_q));
}
FUNCTION s_connect($host, $base, $user, $pass)
{
$host = mysql_connect($host, $user, $pass);
if(!$host)
{
exit(s_error(0));
}
$base = mysql_select_db($base, $host);
if(!$base)
{
exit(s_error(1));
}
else
{
return TRUE;
}
}
FUNCTION s_object($sql, $out)
{
$q = s_array($sql);
return $q[$out];
}
FUNCTION s_query($_q)
{
return mysql_query(s_filter($_q)) or die(s_error(3));
}
FUNCTION s_array($_q)
{
$q = s_query($_q);
return mysql_fetch_array($q);
}
FUNCTION s_insert($base, $table, $a1, $a2)
{
$x = 0;
$string = "INSERT INTO `".$base."`.`".$table."` (";
foreach($a1 as $in)
{
if($x != count($a1) -1)
{
$tables .= "`".$in."`, ";
$x++;
}
else
{
$tables .= "`".$in."`) VALUES (";
$x=0;
}
}
foreach($a2 as $in)
{
if($x != count($a2) -1)
{
$tables .= "'".$in."', ";
$x++;
}
else
{
$tables .= "'".$in."');";
}
}
$final = $string . $tables;
return str_replace("`NULL`", "NULL", $final);
}
?>
Testing Script:
include("connect.php");
include("sql.lib.php");
print_r(s_array("SELECT * FROM `users`"));
s_object("SELECT `blog` from `models` WHERE id =", "$_GET['id']")
Thanks for any help you guys can offer !