Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting data from mySQL

Status
Not open for further replies.

fortytwo

Technical User
Apr 18, 2000
206
GB
Hi All,

I am using the following code to pull data from a mySQL database:

[tt]$q = "SELECT * FROM $table";
$result = (Query $dbh_mysql $q || die "Select failed \n
($Mysql::db_errstr)\n");

print &quot;$result<br>\n&quot;;[/tt]

and it outputs the string:

Mysql::Statement=HASH(0x101826a4)

to the screen (web page). But this is not the information in the database. I want to get some specific information! How do I get this? I really want to select specific information like this:

[tt]$q = &quot;SELECT * FROM $table WHERE (uniq_id = $id)&quot;;
$result = (Query $dbh_mysql $q || die &quot;Select failed \n
($Mysql::db_errstr)\n&quot;);
$num_rows=$result->uniq_id; #Script seems to crash here
print &quot;$num_rows<br>\n&quot;;[/tt]

but the script seems to crash at the point indicated. I know the database is there and I can insert data into it so connection is fine but does anyone know how I can get data out of it!

Thanks.




fortytwo
will@hellacool.co.uk
 
Hi Will,

Thought for a minute you were using the DBI there, but I don't think so... How are you getting access to MySql then?

Mike
michael.j.lacey@ntlworld.com
 
Hi Mike, I am using

[tt]use mySQL;[/tt]

as I don't think there are any other modules installed on the server. I have actually sorted *that* problem out by using the following line:

[tt]%hash = $result->fetchhash;[/tt]

but would you believe it, I have another one :) I can get the hash using the line:

[tt]$q = &quot;SELECT * FROM $table&quot;;[/tt]

but the line:

[tt]$q = &quot;SELECT * FROM $table WHERE (uniq_id = $id)&quot;;[/tt]

throws back a premature end of script header error. I really need to select individual records and not the whole lot as the first select statement does. $id contains the correct information.



fortytwo
will@hellacool.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top