繁体   English   中英

SQLSTATE [HY000]错误,当我尝试使用phpmyadmin在PDO中连接本地数据库时,无法连接到mysql服务器时发生错误

[英]SQLSTATE[HY000] error,cant connect to mysql server error occurs when i tried to connect the local database in PDO using phpmyadmin

我尝试使用PDO将页面与本地服务器中的phpmyadmin连接,但我无法连接至该页面,并且我收到SQLSTATE错误,有人可以通过它帮助我。

config.php:
<?Php
$dbhost_name = "localhost";
$database = "seekouttech";// database name
$username = "root"; // user name
$password = ""; // password 

//////// Do not Edit below /////////
try {
$dbo = new PDO('mysql:host=localhost;dbname='.$database, $username, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?> 
pagination1.php

<meta http-equiv="X-UA-Compatible" content="IE=8" />

<?php include "./includes/menu_include.php";
$t=$_GET['id2'];
echo $t;
 $nws_id = $t;
?>
<?Php
include "config.php";           // All database details will be included here 
$page_name="pagination1.php"; 
$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start)){
echo "Data Error";
exit;
}


$eu = ($start - 0); 
$limit = 10;                                 // No of records to be shown per page.
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit; 



$query2=" SELECT * FROM comment where newsid='$t' ";
$count=$dbo->prepare($query2);
$count->execute();
$nume=$count->rowCount();
$query=" SELECT * FROM comment  limit $eu, $limit ";
foreach ($dbo->query($query) as $row) {

echo $row[name]; 
}
if($nume > $limit ){
if($back >=0) { 
print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>"; 
} 

$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> ";
}
$l=$l+1;
}

if($this1 < $nume) { 
print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} 

?>
<div class="main-content-top">  
<div class="main-wrapper">  
<div class="row">
<div class="large-6 columns">
<h2>Blog</h2>
</div>        
<div class="large-6 columns">
<ul class="breadcrumbs right" style="font- size:18px;">
<li style="text-transform:none;">You are here: </li>
<li><a href="index.php">HOME</a></li>
<li><span><a href="blog.php">BLOG</a></span></li>
<li><span>BLOG DETAILS</span></li>
</ul>
</div>
</div>
</div>      
</div>
<div class="main-wrapper">
<div class="content_wrapper">
<div class="row">
<div class="large-8 columns">
<article class="post single-post">
<?php
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result_comment=mysql_query("select newsid from comment where newsid='$t' ");
$count = mysql_num_rows($result_comment);
$result = mysql_query("SELECT * FROM news where newsid='$t'");
while($row = mysql_fetch_array($result))
{
 ?>
<div class="post_img">
<img class="post_image" src="display_image.php?
pic_id=<?php echo $row['id']; ?>" alt="post title">
<ul class="meta">
<li><i class="icon-comment"></i><?php echo $count." comments";?></li>
<li><i class="icon-calendar"></i><?php echo $row['date']; ?></li>
</ul>
</div>
<h3><?php  echo $row['heading']?></h3>
<p class="post_text" style="text-align:justify;"><?php  echo $row['description']?></p>
</article>      
<div class="comments">
<h4 class="color comment_count"><?php echo $count." comments";?></h4>
<div class="com_meta">
<span class="user_name"><br>
<?php
$result_comment1=
mysql_query("select * from comment where newsid='$t' ORDER BY id DESC   ");
while($row9 = mysql_fetch_array($result_comment1))
{
echo "<b>".$row9['name']."</b>";
?><span class="com_date"><?php echo $row9['date'];?></span><br>
<p class="com_text"><?php echo $row9['comment'];?>
</p>
<?php }
?>
</div>
<div class="com_content">
</div>
</div>
</div>
<?php
}mysql_close();
?>      
<aside class="large-4 columns">
<div class="widgets">
<div class="section-container tabs" data-section="tabs">
<section class="section">
<p class="title"><a href="#"><i class="icon-random"></i> </a></p>
<div class="content">
<marquee direction="up" scrollamount="1">
<?php 
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result2=mysql_query("SELECT * FROM news  ORDER BY id ASC limit 4");
while($row2 = mysql_fetch_array($result2))
{
$id3=$row2['newsid'];
?> 
<p style="margin-top:-6px;"><a href="blog-details.php?id2=<?php echo $id3;?>">
<?php 
$desc2=$row2['heading'];
echo SUBSTR($desc2,0,40);
echo "....";
?> </a>
</p>
<?php   
}mysql_close();
?>
</marquee>
</div>
</section>
<section class="section">
<p class="title"><a href="#"><i   class="icon-comment-alt"></i></a></p>
<div class="content">
<ul class="categories">
<?php
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result_comment=mysql_query("select * from comment where newsid='$t' ");
//echo $t;
while($row9 = mysql_fetch_array($result_comment))
{
echo '<br>'.$row9['comment'];?>&nbsp;&nbsp;----<h7 style="color:#000000; font:bold">
<?php
echo $row9['name'];
?>
</h7>
<?php
}
mysql_close();
?>
</ul>
</div>
</section>
</div>
</div>
<div class="widgets" style="clear:both;">
<h3>Tags</h3>           
<ul id="tags">
<li><a href="portfolio.php" class="button small">App Development</a></li>
<li><a href="portfolio.php" class="button small">Web Design</a></li>
<li><a href="portfolio.php" class="button small">User Interface</a></li>
<li><a href="portfolio.php" class="button small">Branding</a></li>
</ul>
<div class="clearfix"></div>    
</div>
<div class="widgets">
<h3>Services</h3>
<ul id="example1" class="accordion">
<li>
<div class="handle"><span><i></i>
</span><a href="portfolio.php">Logo Design</a>  </div>
</li>
<li>
<ul class="panel loading">
<li>How about&hellip;</li>
<li>&hellip; a list &hellip;</li>
<li>&hellip; of items?</li>
</ul>
</li>
<li>
<p class="panel loading">An image in a paragraph.</p>
</li>
<li><div class="handle"><span><i></i>
</span><a href="portfolio.php">On-line Marketing</a></div>
</li>
<div class="widgets">
<?php 
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result5=mysql_query("SELECT * FROM quoteday ORDER BY id DESC limit 1");
while($row5 = mysql_fetch_array($result5))
{
?>
<h3>Quote of the Day</h3>
<div class="panel">
<p>
<?php echo'"';
echo $row5['quoteoftheday'];
echo '"';   
?>
</p>
</div>
<?php
}
mysql_close();
?>
</div>
</aside>
</div>
</div>           
</div>   
<?php include "./includes/footer_section.php";?>

这是我要实现分页的代码,我想使用mysql检索从数据库中获取的所有注释。

显而易见的答案是mysql没有运行。

请尝试在命令行上连接到mysql以确认它正在运行

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM