Hi,
I've been having some very wierd problems using arrays and the database
functions for mysql_fetch_array and mssql_fetch_array. (Running on Windows
2000). Please see the comments in the code below.
#connect to the ms sql db
#(the problem also occurs when using a mysql db)
$connsrc = mssql_connect("dellserver","vbweb", "password");
#select the db
mssql_select_db("vbwcontent", $connsrc);
#execute the query
$query = mssql_query("SELECT TOP 10 * FROM dir_items");
#get the number of fields in the query
$count=mssql_num_fields($query);
while ($data=mssql_fetch_array($query)) {
#in theory, count($data) should return the same number
#as the $count variable, but it returns twice the amount
#presumably because of the use of keys and indicies?
#loop through the returned data
for ($i=0;$i<$count;$i++) {
#we can try to do this 2 ways, both cause access errors
#use the array position. However, once we use this,
#it appears we cannot use the named field... try it!
$data[$i]=str_replace("'","''",$data[$i]);
#alternatively, try getting the name of the field, and reference
#it using it's named field...
$pos=mssql_field_name($query,$i);
$data[$pos]=str_replace("'","''",$data[$pos]);
#and we still get 'PHP has encountered an Access Violation at
0146E027',
or
#Warning: Cannot use a scalar value as an array in D:\Virtual
Hosts\vbweb.co.uk_new\bin\importdata.php on line 27
#it appears that PHP is getting it's memory in a mess, as
#some very weird values are returned...
}
echo "INSERT INTO dir_items (authorid,url) VALUES
($data[memberid],'$data[url]')";
}
Can any one tell me why this is happening, and any way to work around it?
Regards,
- James
Editor, VB Web
==================
Web - http://www.vbweb.co.uk
Email - [EMAIL PROTECTED]
ICQ# - 60612011
Fax - +44(0)8707052859
==================
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]