Search code examples
phpruntime-errorerror-suppression

Why do I have to suppress errors for my function to work


Hi I have a script to log people into my site and within the script is this method (I have changed the values)

$con=mysql_connect("mydbdomain", "mydbusername", "mypassword");

Now I downloaded a open source file upload program and uploaded it to my server and only allow users who are in the database to use it. It all works great. I however then go and edit the php code which handles the file uploads so that every time a user uploads a file it goes into a directory that matches their username.

<?php
/*
* jQuery File Upload Plugin PHP Class 7.1.4
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*
* Modified by leathan AxE
*/

class UploadHandler
{
...
...
...
...
    function foo() { ... }
}
?>

The function above named foo is where i connect to the db and extract the value of the future directory. But whenever i have this line.

$con=mysql_connect("mydbdomain", "mydbusername", "mypassword");

instead of

$con=@mysql_connect("mydbdomain", "mydbusername", "mypassword");

nothing works. why is it when i use @ and suppress errors it all works? Why are there errors? The files are uploaded into the usernames directory perfectly only when using @. I just want to understand what is happening. I dont understand how there can be an error because i use the line

$con=mysql_connect("mydbdomain", "mydbusername", "mypassword");

in other files and it always works.


Solution

  • mysql_connect is deprecated and shouldn't be used. Probably your provider have E_DEPRECATED error level and you get warning whenever you use mysql_connect.

    Try using PDO