-1

Disclaimer

While I know the mysql_[command] functions are depreciated, this is for a school project and I started before they became depreciated. I don't get marked on the "up-to-date-ness" of the functions used, only the complex-nature of the program I have written therefore there was no incentive to change to PDO or mysqli. I have to include a variable-listing of all the variables I have used (including data type...) even though they aren't defined in the same way as vb.net for example.

The big question I have!

What is the data type of the variable $link in the code listed below? Where a data type is for example a string, integer, boolean value, etc...

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
Justice
  • 169
  • 1
  • 2
  • 9
  • It should be a resource if connected successful. – xdazz Apr 24 '14 at 09:58
  • 1
    Doesn't the documentation answer this? – Barmar Apr 24 '14 at 09:59
  • Is a resource a data type? Or is it PHP-specific? The documentation doesn't answer this that I can see. – Justice Apr 24 '14 at 10:01
  • 1
    It's a PHP specific data type: http://php.net/manual/en/language.types.resource.php All data types are language specific, it's just that most languages share many similar types and ideas about those types. – deceze Apr 24 '14 at 10:01
  • 1
    Just to make this clear: This is not the Google Search Input Field. This is Stack Overflow ;-) – Andresch Serj Apr 24 '14 at 10:01
  • Deceze actually answered my question - it was my misunderstanding of the documentation that a resource is a data type. I assumed that because I haven't heard of it in this context that I was looking in the wrong place. – Justice Apr 24 '14 at 10:05
  • @Justice Also consider switiching to mysqli_connect since, as you've read in the documentation, mysql_* is deprecated. http://www.php.net/manual/en/function.mysqli-connect.php – Andresch Serj Apr 24 '14 at 10:29

1 Answers1

3

If it connects successfully it'll be a resource identifier, otherwise a boolean:

Returns a MySQL link identifier on success or FALSE on failure.

See: http://php.net/manual/en/function.mysql-connect.php

VF_
  • 2,627
  • 17
  • 17