psquillace Posted December 30, 2007 Share Posted December 30, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/ Share on other sites More sharing options...
cooldude832 Posted December 30, 2007 Share Posted December 30, 2007 $db_select = mysql_select_db("widget_corp","$connection"); that is incorrect do $db_select = mysql_select_db("widget_corp",$connection); Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/#findComment-426129 Share on other sites More sharing options...
psquillace Posted December 30, 2007 Author Share Posted December 30, 2007 yes, I know it is incorrect. My question was why no double quotes arround that handle $connection? thanks for your help thought, paul Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/#findComment-426133 Share on other sites More sharing options...
cooldude832 Posted December 30, 2007 Share Posted December 30, 2007 read up on qutation user, I believe its because you are refrences a resource Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/#findComment-426138 Share on other sites More sharing options...
GingerRobot Posted December 30, 2007 Share Posted December 30, 2007 Indeed. By quoting the variable in double quotes, PHP will attempt to evaluate the variable. When it does this, it will give a Resource ID. The same thing will happen if you were to echo the variable. Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/#findComment-426142 Share on other sites More sharing options...
psquillace Posted December 30, 2007 Author Share Posted December 30, 2007 Hrmm, so because I am working with this function by putting it in double quotes I am telling it to parse it as a variable not as a resource? Ok, I think I got it. thanks all for your help, Paul Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/#findComment-426147 Share on other sites More sharing options...
cooldude832 Posted December 30, 2007 Share Posted December 30, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/#findComment-426148 Share on other sites More sharing options...
Barand Posted December 30, 2007 Share Posted December 30, 2007 "$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. Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/#findComment-426152 Share on other sites More sharing options...
GingerRobot Posted December 30, 2007 Share Posted December 30, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/#findComment-426172 Share on other sites More sharing options...
cooldude832 Posted December 30, 2007 Share Posted December 30, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/#findComment-426178 Share on other sites More sharing options...
Barand Posted December 30, 2007 Share Posted December 30, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/#findComment-426185 Share on other sites More sharing options...
cooldude832 Posted December 30, 2007 Share Posted December 30, 2007 I think you know what I meant, they return data that can be worked on outside of a resource, Quote Link to comment https://forums.phpfreaks.com/topic/83754-solved-why-no-double-quotes-here/#findComment-426190 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.