Frequently Asked Questions

Other Languages: Dansk Deutsch Ελληνικά English Español Suomi Français Indonesian Italiano Japanese Korean Malay Bokmål Nederlands Polski Português - Brasil Português - Portugal Русский Svenska Thai Türkçe Українська Vietnamese Chinese Taiwan Chinese

Pagkokonekta Ng Aking MySQL Gamit Ang PHP

Print this Article
Last Updated: February 18, 2015 11:50 AM

Maaari ninyong ma-access ang mga database ng MySQL nang direkta sa pamamagitan ng mga PHP script. Pinapahintulutan kayo nito na basahin at isulat ang mga data sa inyong database nang direkta mula sa inyong website.

Pagkokonekta sa Aking MySQL Gamit ang PHP

  1. Makakakonekta sa inyong MySQL server gamit ang sumusunod na mysql_connect pahayag. Halimbawa:

    $con = mysql_connect('HOSTNAME','USERNAME','PASSWORD');

    Para sa tulong sa inyong mysql_connect na impormasyon, basahin ang Viewing Your Database Details with Shared Hosting Accounts.

  2. Piliin ang database na nais ninyong i-access gamit ang mysql_select_db. Halimbawa:

    mysql_select_db(
    'DATABASENAME', $con)
    Kung saan ang 'DATABASENAME' ay ang pangalan ng inyong database — ipinapakita din nito ang mga detalye ng pahina ng inyong database.

Makalipas na matatag ang koneksyon at mapili ang database, maaari ninyo itong tanungin gamit ang PHP.

Para matulungan kayo lumikha ng inyong sariling string para sa koneksyon, nagsama kami ng isang halimbawa sa ibaba.

Halimbawa ng MySQL na String para sa Koneksyon gamit ang PHP

<?php //Sample Database Connection Syntax for PHP and MySQL. //Connect To Database $hostname="your_mysqlserver.secureserver.net"; $username="your_dbusername"; $password="your_dbpassword"; $dbname="your_dbusername"; $usertable="your_tablename"; $yourfield = "your_field"; mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>"); mysql_select_db($dbname); # Check If Record Exists $query = "SELECT * FROM $usertable"; $result = mysql_query($query); if($result) { while($row = mysql_fetch_array($result)) { $name = $row["$yourfield"]; echo "Pangalan: ".$name.""; } } ?> <p>Para sa karagdagang impormasyon, basahin ang MySQL Functions na pahina sa <a href="http://us.php.net/mysql">php.net</a>.</p> </div> <img src="../http/img.secureserver.net/MS_36970.gif" class="gdti" border="0" width="1" height="1" style="width: 1px; height: 1px; border: 0; margin: 0; padding: 0; position: absolute; top: 1em; left: 0.5em;" alt="" /> <div id="rating"><strong>Rate this article: </strong><ul class="star-rating"><li><a rel="nofollow" href="MS_28450.html" title="Not helpful">Not helpful</a></li><li><a rel="nofollow" href="MS_28450.html" title="Somewhat helpful">Somewhat helpful</a></li><li><a rel="nofollow" href="MS_28450.html" title="Helpful">Helpful</a></li><li><a rel="nofollow" href="MS_28450.html" title="Very Helpful">Very Helpful</a></li><li><a rel="nofollow" href="MS_28450.html" title="Solved my problem">Solved my problem</a></li></ul><div class="bottom"></div></div> </div> <div id="base" style="clear: both"></div> <!-- pageok --> <!-- googleoff: index --> <!-- End Content --> </div> <!-- End Body Wrap --> <div id="footer"> Copyright &copy; 2005 - 2015. All rights reserved. <a href="http://www.securepaynet.net/agreements/ShowDoc.aspx?pageid=privacy&prog_id=ixonecom">Privacy Policy</a> </div> <!-- pageok --> <!-- googleon: index --> </body> </html>