I am using two pieces of script...
here is the database class
class sql_wrapper{
var $dbhost;
var $dbuser;
var $dbpass;
var $dbase;
var $sql_query;
var $mysql_link;
var $sql_result;
var $query_count;
function sql_wrapper($dbhost,$dbuser,$dbpass,$dbase)
{
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpass = $dbpass;
$this->dbase = $dbase;
$this->mysql_link = '0';
$this->query_count = '0';
$this->sql_result = '';
$this->connection();
}
//make connection to the database
function connection(){
$this->mysql_link = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpass ) or $this->error( mysql_error( $this->mysql_link ), $this->sql_query, mysql_errno( $this->mysql_link ) );
@mysql_select_db( $this->dbase ) or $this->error( mysql_error( $this->mysql_link ), $this->sql_query, mysql_errno( $this->mysql_link ) );
}
//display any errors in readable format
function error( $error_msg, $sql_query, $error_no )
{
$error_date = date("F j, Y, g:i a");
//Heredoc Strings must be on the far left lines
$error_page = <<<EOD
<html><head><title>mySQL database Error</title>
<style>P,BODY{ font-family:arial,sans-serif; font-size:11px; }</style></head><body>
<br><br><blockquote><b>There appears to be an error while trying to complete your request.</b><br>
You can try to go back and try again by clicking <a href="javascript:history.go(-1);">here</a>, if you
still get the error you can contact the site administrator by clicking <a href='mailto:haiden@asciant.net?subject=SQL+Error'>here</a>
<br><br><b>Error Returned</b><br>
<form name='mysql'><textarea rows="15" cols="60">mySQL query error: {$sql_query}
mySQL error: {$error_msg}
mySQL error code: {$error_no}
Date: {$error_date}</textarea></form><br>We apologise for any inconvenience</blockquote></body></html>
EOD;
echo $error_page;
}
function sql_query( $sql_query )
{
$this->sql_query = $sql_query;
$this->sql_result = @mysql_query( $sql_query, $this->mysql_link );
if (!$this->sql_result)
{
$this->error( mysql_error( $this->mysql_link ), $this->sql_query, mysql_errno( $this->mysql_link ) );
}
$count = $this->query_count;
$count = ($count + 1);
$this->query_count = $count;
}
//close database link
function close()
{
mysql_close( $this->mysql_link );
}
function num_rows()
{
$mysql_rows = mysql_num_rows( $this->sql_result );
if (!$mysql_rows)
{
$this->error( mysql_error( $this->mysql_link ), $this->sql_query, mysql_errno( $this->mysql_link ) );
}
return $mysql_rows;
}
function affected_rows()
{
$mysql_affected_rows = mysql_affected_rows( $this->mysql_link );
return $mysql_affected_rows;
}
function fetch_array()
{
if ( $this->num_rows() > 0 )
{
$mysql_array = mysql_fetch_assoc( $this->sql_result );
if (!is_array( $mysql_array ))
{
return FALSE;
}
return $mysql_array;
}
}
function fetch_rows()
{
if ( $this->num_rows() > 0 )
{
$mysql_array = mysql_fetch_row( $this->sql_result );
if (!is_array( $mysql_array ))
{
return FALSE;
}
return $mysql_array;
}
}
function query_count()
{
return $this->query_count;
}
}
and here is the script
include ("includes/sql_db_wrapper.php");
include ("includes/functions.php");
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'urnid10t';
$dbase = 'ctfstores';
// Make Database connection
$database = new sql_wrapper($dbhost,$dbuser,$dbpass,$dbase);
$select_users = "SELECT * FROM user_upload";
$database->sql_query($select_users);
while($data = $database->fetch_array()){
/*echo "<pre>";
print_r($results);
echo "</pre>";*/
/* zen cart customers fields */
$customers_id = "";
$customers_gender = "";
$customers_firstname = addslashes($data['firstname']);
$customers_lastname = addslashes($data['lastname']);
$customers_dob = "";
$customers_email_address = $data['email'];
$customers_nick = "";
$customers_default_address_id = addslashes($data['address1']);
$customers_telephone = addslashes($data['phonenumber']);
$customers_fax = "";
$customers_password = addslashes($data['password']);
$customers_newsletter = "";
$customers_group_pricing = "";
$customers_email_format = "";
$customers_authorization = "";
$customers_referral = "";
$customers_paypal_payerid = "";
$customers_paypal_ec = "";
$customers_username = $data['username'];
echo '<br/>Firstname:'.$customers_firstname.'<br/>Lastname:'.$customers_lastname.'<br/>Email:'.$customers_email_address;
$data_import = "INSERT IGNORE INTO zen_customers (`customers_username`) VALUES ('$customers_username')";
$database->sql_query($data_import);
}
I am getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\apache2triad\htdocs\vhosts\customer_uploader\includes\sql_db_wrapper.php on line 103
anyone able to tell me why? I have used this wrapper to do insert statements before. Dont know why it isnt working this time.
Thanks