Jump to content

[SOLVED] Why no double quotes here....


psquillace

Recommended Posts

hello all:

 

In connecting and selecting my database I wrote the following:

 

<?php

$connection = mysql_connect("127.0.0.1","root","playingcards");

if (!$connection) {

die("Connection to Database Failed: " . mysql_error());

}

 

$db_select = mysql_select_db("widget_corp","$connection");

if (!db_select) {

die("Cannot Select database widget_corp: " . mysql_error());

}

?>

 

However I kept getting an error that was driving me crazy..... till I figured what the issue was, I was using double quotes around my handle $conncection when in fact, there should not have been any.

 

My question is, Why? I thought just like in connecting where I needed each argument IP, user, pass to have quotes why should I not use that for my connection.

 

Thanks for any help or advice on this,

 

Paul

Link to comment
https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/
Share on other sites

well certain things  are more than just a number or an integer, its one of the weaknesses to php is that all variables are defnined very similarlly so you can start to get lazy and not realize you are acting on a string when you thought it was an integer and so forth.

Mysql creates resources the only String output from Mysql comes from a mysql_result, mysql_fetch or mysql_insert_id and their derrivatives mysql_query and mysql_connection are both resource generating functions.

"$connection" casts it as a string, instead of an integer value.

 

So if it's resource #3, the string version has a byte value of 0x33 whereas the integer value is 0x03.

 

String/int conversion is usually automatic in PHP as it is typeless, but it is significant when dealing with resource handles.

well certain things  are more than just a number or an integer, its one of the weaknesses to php is that all variables are defnined very similarlly so you can start to get lazy and not realize you are acting on a string when you thought it was an integer and so forth.

Mysql creates resources the only String output from Mysql comes from a mysql_result, mysql_fetch or mysql_insert_id and their derrivatives mysql_query and mysql_connection are both resource generating functions.

 

I hardly think you can call the fact that PHP is a weakly-typed language one of its weaknessess. Its simply part of the language.

I hardly think you can call the fact that PHP is a weakly-typed language one of its weaknessess. Its simply part of the language.

Coming from stricter languages like C, Java etc. you will not make the common mistakes, but if you start with php its a weakness if you move to c, java

mysql_query and mysql_connection are both resource generating functions.

 

Agreed

 

... the only String output from Mysql comes from a mysql_result, mysql_fetch or mysql_insert_id and their derrivatives

 

mysql_result returns whatever the column type is

mysql_fetch_xxx returns and array

mysql_insert_id returns the last generated INT id

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.