/fmake/libs/dataBaseController/utlMySqlWork.php

https://github.com/fmake/fmake · PHP · 114 lines · 87 code · 16 blank · 11 comment · 4 complexity · 3466f9f270bbe95510e74f55c53b38eb MD5 · raw file

  1. <?php
  2. function errorExit()
  3. {
  4. echo "</td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table>\n";
  5. echo "<br><center><font color=red size=+2><?=_ERROR?></font><br><?=_SORRY?></center>\n";
  6. exit();
  7. }
  8. class utlMySqlWork
  9. {
  10. private $UserName;
  11. private $Password ;
  12. private $DatabaseName;
  13. private $HostName;
  14. private $Port ;
  15. private $DbCharSet ;
  16. private $ProjectName ;
  17. private $SelfName = null;
  18. private $Connection_id = null;
  19. private $CurrentResult = null;
  20. private $DoNotFreeResult = null;
  21. /**
  22. *
  23. * @var dataBaseController_logFile
  24. */
  25. private $log;
  26. function __construct($FileName,$db_user_name,$db_user_pas,$db_name,$db_host_name,$db_port,$db_crarset,$pr_name )
  27. {
  28. $this->UserName = $db_user_name;
  29. $this->Password = $db_user_pas;
  30. $this->DatabaseName = $db_name;
  31. $this->HostName = $db_host_name;
  32. $this->Port = $db_port;
  33. $this->DbCharSet = $db_crarset;
  34. $this->ProjectName = $pr_name;
  35. $this->SelfName=$FileName;
  36. }
  37. function addLog(dataBaseController_logFile $log){
  38. $this -> log = $log;
  39. }
  40. function checkError($ss,$errLine) // �������� �� ������
  41. {
  42. if(mysql_errno($this->Connection_id)!=0)
  43. {
  44. $date=date("y-m-d H:i:s");
  45. echo "Project: $this->ProjectName \n\n<br>Date: $date <br>Script: $this->SelfName <br>Line: $errLine <br>Error(".mysql_errno()."):".mysql_error()."\n\n <br>in query: $ss <br><br><br>";
  46. ErrorExit();
  47. }
  48. }
  49. /**
  50. *
  51. * Соеединение к базе данных
  52. * @param $Line
  53. * @param $new_link bool если второе соединение к базе данных то необходимо указывать true
  54. */
  55. function connect($Line,$new_link = false)
  56. {
  57. $this->Connection_id = mysql_connect($this->HostName.":".$this->Port,$this->UserName,$this->Password,$new_link);
  58. $this->checkError("Connect to ".$this->HostName,$Line);
  59. //$this->query("SET CHARACTER SET ".$this->DbCharSet,$Line);
  60. $this->query("SET NAMES ".$this->DbCharSet,$Line);
  61. mysql_select_db($this->DatabaseName,$this->Connection_id);
  62. $this->checkError("Select ".$this->DatabaseName,$Line);
  63. }
  64. function query($ss,$Line)
  65. {
  66. if($this -> log){
  67. $this -> log -> add($ss);
  68. }
  69. if($this->CurrentResult>1){ if(!$this->DoNotFreeResult){ mysql_free_result($this->CurrentResult); }}
  70. $this->CurrentResult=mysql_query($ss,$this->Connection_id);
  71. $this->checkError($ss,$Line);
  72. return $this->CurrentResult;
  73. }
  74. function data_seek($i)
  75. {
  76. mysql_data_seek($this->CurrentResult, $i);
  77. }
  78. function fetch_array($type = MYSQL_BOTH)
  79. {
  80. return mysql_fetch_array($this->CurrentResult, $type);
  81. }
  82. function fetch_object()
  83. {
  84. return mysql_fetch_object($this->CurrentResult);
  85. }
  86. function num_rows()
  87. {
  88. return mysql_num_rows($this->CurrentResult);
  89. }
  90. function insert_id()
  91. {
  92. return mysql_insert_id($this->Connection_id);
  93. }
  94. function disconnect()
  95. {
  96. mysql_close($this->Connection_id);
  97. }
  98. }