Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8944411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:00:53+00:00 2026-06-15T12:00:53+00:00

I get an error trying to connect to my mysql database, I’m quite a

  • 0

I get an error trying to connect to my mysql database, I’m quite a PHP/mysql amateur so I hope you guys can help me out since I’m stuck.

Warning: mysql_query() [function.mysql-query]: 
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'\
(2) in /public/sites/www.kernlab.nl/website/index.php on line 13

Warning: mysql_query() [function.mysql-query]: A link to the server could not be
established in /public/sites/www.kernlab.nl/website/index.php on line 13
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Below is how I try to connect to my database:

<?php
$db_host = "host";
$db_username = "user";
$db_password = "pass";
$db_database = "db";
$link = mysqli_connect($db_host,$db_username,$db_password) or die("Cannot connect");
  mysqli_select_db($link, $db_database) or die("Cannot select database");
?>

This how I try to echo the data:

<?php
$query="SELECT * FROM ditdoenweblokken ORDER BY id DESC";
$result = mysql_query($query) or die(mysql_error()) ;
while($rij = mysql_fetch_array($result)){  
?>
<li><a style="height:150px;width:150px;" class="fancybox" href="#inline<?php echo($rij['id']);?>">
    <p style="font-weight:bold;"><?php echo($rij['titel']);?></p>
    <?php echo($rij['quote']);?></a>
</li>
<?php
}
?>

I get the feeling the problem is not in the script itself but somewhere in the mysql server? Hope you guys can help since I’m stuck.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:00:56+00:00Added an answer on June 15, 2026 at 12:00 pm

    I think your problem might be that you are connecting to the server using mysqli_connect but you are trying to run a query using mysql_query.

    Try using mysqli to run the query.

    Here is the manual for mysqli MYSQLi Manual

    On a side note, this might help when thinking about how you get your data from your database and the security of it:

    Net Tuts – The Problem with PHP’s Prepared Statements

    You can either change the way you connect to you server, using mysql like so:
    mysql_connect(servername,username,password);

    However this is not secure. Or you can change the way you are doing the query as stated before.

    First you need to get the connection so lets say you store it in $mysqli Then we can run the query:

    $result = $mysqli->query("SELECT * FROM ditdoenweblokken ORDER BY id DESC);
    

    Now you can check to see if anything has been returned from the query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to connect to Mysql database with following Php code. But I get
i get this following error when i am trying to connect my localhost mysql
I am trying to connect to MySQL database with Java and I get the
I am trying to connect to a remote mysql database but I get the
trying to get my first little PHP script to connect to a local mySql
I am trying to get data from MySQL database but in the php file
When trying to connect to mysql I always get this error: java.sql.SQLException: No suitable
I'm trying to connect to a mysql database using Connector/J but get the same
I am trying to connect to a MySQL database using the mysql_connect() command however
I' trying to get some data from Oracle via ODBC to mySQL database. And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.