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
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.

Link to comment
Share on other sites

"$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.

Link to comment
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.

 

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.