Foros del Web » Programando para Internet » PHP »

Error de Linea

Estas en el tema de Error de Linea en el foro de PHP en Foros del Web. Buenas tardes: Soy nuevo en éste foro y en programacion PHP, tengo un error enuna linea de codigo y no se como resolverlo espero me ...
  #1 (permalink)  
Antiguo 05/03/2015, 10:51
 
Fecha de Ingreso: marzo-2015
Mensajes: 6
Antigüedad: 9 años, 1 mes
Puntos: 0
Error de Linea

Buenas tardes:

Soy nuevo en éste foro y en programacion PHP, tengo un error enuna linea de codigo y no se como resolverlo espero me puedan ayudar.

El codigo es:

500 public static function isSupported()
501 {
502 return in_array('mysql', PDO::getAvailableDrivers());
503 return class_exists('PDO') && in_array('mysql',
504 PDO::getAvailableDrivers());
506 }

Me está marcando un error de sintaxis en la linea 500

Me pueden ayudar??
  #2 (permalink)  
Antiguo 05/03/2015, 11:02
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: Error de Linea

Publica el error que te envía en esa linea
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.
  #3 (permalink)  
Antiguo 05/03/2015, 11:09
 
Fecha de Ingreso: marzo-2015
Mensajes: 6
Antigüedad: 9 años, 1 mes
Puntos: 0
Respuesta: Error de Linea

Hola hhs, gracias por responder.

Esto es lo que arroja el sitio

Parse error: syntax error, unexpected T_PUBLIC in /home/dicte7zp/public_html/miportal/libraries/joomla/database/driver/pdomysql.php on line 500

Es un sitio creado en Joomla 3.4.0
  #4 (permalink)  
Antiguo 05/03/2015, 11:10
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: Error de Linea

Si la función no esta dentro de una clase no requiere el public
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.
  #5 (permalink)  
Antiguo 05/03/2015, 11:23
 
Fecha de Ingreso: marzo-2015
Mensajes: 6
Antigüedad: 9 años, 1 mes
Puntos: 0
Respuesta: Error de Linea

Todo esto salio por que la página de configuracion global de joomla marcaba error y no cargaba bien la página, buscando en la web encontré en joomla docs que era necesario un parche que es el siguiente

From 30db89348bd2e52789fd9232782abd818c99e4c2 Mon Sep 17 00:00:00 2001
From: Michael Babker <[email protected]>
Date: Wed, 25 Feb 2015 08:47:09 -0500
Subject: [PATCH] Add a class_exists check to PDO MySQL driver

---
libraries/joomla/database/driver/pdomysql.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libraries/joomla/database/driver/pdomysql.php b/libraries/joomla/database/driver/pdomysql.php
index 4df9a15..d4dc6c7 100644
--- a/libraries/joomla/database/driver/pdomysql.php
+++ b/libraries/joomla/database/driver/pdomysql.php
@@ -99,7 +99,7 @@ public function connect()
*/
public static function isSupported()
{
- return in_array('mysql', PDO::getAvailableDrivers());
+ return class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers());
}

/**

al cargar el codigo en el archivo php se me lleno de errores, pude indentificar las notas y al encerrarlas solo me quedo el error de la linea 500
  #6 (permalink)  
Antiguo 05/03/2015, 11:28
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: Error de Linea

Publica el código original, pero lo que tenias que hacer era borrar la linea:
Código PHP:
Ver original
  1. return in_array('mysql', PDO::getAvailableDrivers());
y agregar esta
Código PHP:
Ver original
  1. return class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers());
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.
  #7 (permalink)  
Antiguo 05/03/2015, 12:06
 
Fecha de Ingreso: marzo-2015
Mensajes: 6
Antigüedad: 9 años, 1 mes
Puntos: 0
Respuesta: Error de Linea

Este es el código original, lo adjunto en dos partes

<?php
/**
* @package Joomla.Platform
* @subpackage Database
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

defined('JPATH_PLATFORM') or die;

/**
* MySQL database driver supporting PDO based connections
*
* @package Joomla.Platform
* @subpackage Database
* @see http://php.net/manual/en/ref.pdo-mysql.php
* @since 3.4
*/
class JDatabaseDriverPdomysql extends JDatabaseDriverPdo
{
/**
* The name of the database driver.
*
* @var string
* @since 3.4
*/
public $name = 'pdomysql';

/**
* The character(s) used to quote SQL statement names such as table names or field names,
* etc. The child classes should define this as necessary. If a single character string the
* same character is used for both sides of the quoted name, else the first character will be
* used for the opening quote and the second for the closing quote.
*
* @var string
* @since 3.4
*/
protected $nameQuote = '`';

/**
* The null or zero representation of a timestamp for the database driver. This should be
* defined in child classes to hold the appropriate value for the engine.
*
* @var string
* @since 3.4
*/
protected $nullDate = '0000-00-00 00:00:00';

/**
* The minimum supported database version.
*
* @var string
* @since 3.4
*/
protected static $dbMinimum = '5.0.4';

/**
* Constructor.
*
* @param array $options Array of database options with keys: host, user, password, database, select.
*
* @since 3.4
*/
public function __construct($options)
{
// Get some basic values from the options.
$options['driver'] = 'mysql';
$options['charset'] = (isset($options['charset'])) ? $options['charset'] : 'utf8';

$this->charset = $options['charset'];

// Finalize initialisation.
parent::__construct($options);
}

/**
* Connects to the database if needed.
*
* @return void Returns void if the database connected successfully.
*
* @since 3.4
* @throws RuntimeException
*/
public function connect()
{
parent::connect();

$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
}

/**
* Test to see if the MySQL connector is available.
*
* @return boolean True on success, false otherwise.
*
* @since 3.4
*/
public static function isSupported()
{
return in_array('mysql', PDO::getAvailableDrivers());
}

/**
* Drops a table from the database.
*
* @param string $tableName The name of the database table to drop.
* @param boolean $ifExists Optionally specify that the table must exist before it is dropped.
*
* @return JDatabaseDriverPdomysql Returns this object to support chaining.
*
* @since 3.4
* @throws RuntimeException
*/
public function dropTable($tableName, $ifExists = true)
{
$this->connect();

$query = $this->getQuery(true);

$query->setQuery('DROP TABLE ' . ($ifExists ? 'IF EXISTS ' : '') . $this->quoteName($tableName));

$this->setQuery($query);

$this->execute();

return $this;
}

/**
* Select a database for use.
*
* @param string $database The name of the database to select for use.
*
* @return boolean True if the database was successfully selected.
*
* @since 3.4
* @throws RuntimeException
*/
public function select($database)
{
$this->connect();

$this->setQuery('USE ' . $this->quoteName($database));

$this->execute();

return $this;
}

/**
* Method to get the database collation in use by sampling a text field of a table in the database.
*
* @return mixed The collation in use by the database (string) or boolean false if not supported.
*
* @since 3.4
* @throws RuntimeException
*/
public function getCollation()
{
$this->connect();

// Attempt to get the database collation by accessing the server system variable.
$this->setQuery('SHOW VARIABLES LIKE "collation_database"');
$result = $this->loadObject();

if (property_exists($result, 'Value'))
{
return $result->Value;
}
else
{
return false;
}
}

/**
* Shows the table CREATE statement that creates the given tables.
*
* @param mixed $tables A table name or a list of table names.
*
* @return array A list of the create SQL for the tables.
*
* @since 3.4
* @throws RuntimeException
*/
public function getTableCreate($tables)
{
$this->connect();

// Initialise variables.
$result = array();

// Sanitize input to an array and iterate over the list.
settype($tables, 'array');

foreach ($tables as $table)
{
$this->setQuery('SHOW CREATE TABLE ' . $this->quoteName($table));

$row = $this->loadRow();

// Populate the result array based on the create statements.
$result[$table] = $row[1];
}

return $result;
}

/**
* Retrieves field information about a given table.
*
* @param string $table The name of the database table.
* @param boolean $typeOnly True to only return field types.
*
* @return array An array of fields for the database table.
*
* @since 3.4
* @throws RuntimeException
*/
public function getTableColumns($table, $typeOnly = true)
{
$this->connect();

$result = array();

// Set the query to get the table fields statement.
$this->setQuery('SHOW FULL COLUMNS FROM ' . $this->quoteName($table));

$fields = $this->loadObjectList();

// If we only want the type as the value add just that to the list.
if ($typeOnly)
{
foreach ($fields as $field)
{
$result[$field->Field] = preg_replace("/[(0-9)]/", '', $field->Type);
}
}
  #8 (permalink)  
Antiguo 05/03/2015, 12:07
 
Fecha de Ingreso: marzo-2015
Mensajes: 6
Antigüedad: 9 años, 1 mes
Puntos: 0
Respuesta: Error de Linea

// If we want the whole field data object add that to the list.
else
{
foreach ($fields as $field)
{
$result[$field->Field] = $field;
}
}

return $result;
}

/**
* Get the details list of keys for a table.
*
* @param string $table The name of the table.
*
* @return array An array of the column specification for the table.
*
* @since 3.4
* @throws RuntimeException
*/
public function getTableKeys($table)
{
$this->connect();

// Get the details columns information.
$this->setQuery('SHOW KEYS FROM ' . $this->quoteName($table));

$keys = $this->loadObjectList();

return $keys;
}

/**
* Method to get an array of all tables in the database.
*
* @return array An array of all the tables in the database.
*
* @since 3.4
* @throws RuntimeException
*/
public function getTableList()
{
$this->connect();

// Set the query to get the tables statement.
$this->setQuery('SHOW TABLES');
$tables = $this->loadColumn();

return $tables;
}

/**
* Get the version of the database connector.
*
* @return string The database connector version.
*
* @since 3.4
*/
public function getVersion()
{
$this->connect();

return $this->getOption(PDO::ATTR_SERVER_VERSION);
}

/**
* Locks a table in the database.
*
* @param string $table The name of the table to unlock.
*
* @return JDatabaseDriverPdomysql Returns this object to support chaining.
*
* @since 3.4
* @throws RuntimeException
*/
public function lockTable($table)
{
$this->setQuery('LOCK TABLES ' . $this->quoteName($table) . ' WRITE')->execute();

return $this;
}

/**
* Renames a table in the database.
*
* @param string $oldTable The name of the table to be renamed
* @param string $newTable The new name for the table.
* @param string $backup Not used by MySQL.
* @param string $prefix Not used by MySQL.
*
* @return JDatabaseDriverPdomysql Returns this object to support chaining.
*
* @since 3.4
* @throws RuntimeException
*/
public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
{
$this->setQuery('RENAME TABLE ' . $this->quoteName($oldTable) . ' TO ' . $this->quoteName($newTable));

$this->execute();

return $this;
}

/**
* Method to escape a string for usage in an SQL statement.
*
* Oracle escaping reference:
* http://www.orafaq.com/wiki/SQL_FAQ#How_does_one_escape_special_characters_whe n_writing_SQL_queries.3F
*
* SQLite escaping notes:
* http://www.sqlite.org/faq.html#q14
*
* Method body is as implemented by the Zend Framework
*
* Note: Using query objects with bound variables is
* preferable to the below.
*
* @param string $text The string to be escaped.
* @param boolean $extra Unused optional parameter to provide extra escaping.
*
* @return string The escaped string.
*
* @since 3.4
*/
public function escape($text, $extra = false)
{
$this->connect();

if (is_int($text) || is_float($text))
{
return $text;
}

$result = substr($this->connection->quote($text), 1, -1);

if ($extra)
{
$result = addcslashes($result, '%_');
}

return $result;
}

/**
* Unlocks tables in the database.
*
* @return JDatabaseDriverPdomysql Returns this object to support chaining.
*
* @since 3.4
* @throws RuntimeException
*/
public function unlockTables()
{
$this->setQuery('UNLOCK TABLES')->execute();

return $this;
}

/**
* Method to commit a transaction.
*
* @param boolean $toSavepoint If true, commit to the last savepoint.
*
* @return void
*
* @since 3.4
* @throws RuntimeException
*/
public function transactionCommit($toSavepoint = false)
{
$this->connect();

if (!$toSavepoint || $this->transactionDepth <= 1)
{
parent::transactionCommit($toSavepoint);
}
else
{
$this->transactionDepth--;
}
}

/**
* Method to roll back a transaction.
*
* @param boolean $toSavepoint If true, rollback to the last savepoint.
*
* @return void
*
* @since 3.4
* @throws RuntimeException
*/
public function transactionRollback($toSavepoint = false)
{
$this->connect();

if (!$toSavepoint || $this->transactionDepth <= 1)
{
parent::transactionRollback($toSavepoint);
}
else
{
$savepoint = 'SP_' . ($this->transactionDepth - 1);
$this->setQuery('ROLLBACK TO SAVEPOINT ' . $this->quoteName($savepoint));

if ($this->execute())
{
$this->transactionDepth--;
}
}
}

/**
* Method to initialize a transaction.
*
* @param boolean $asSavepoint If true and a transaction is already active, a savepoint will be created.
*
* @return void
*
* @since 3.4
* @throws RuntimeException
*/
public function transactionStart($asSavepoint = false)
{
$this->connect();

if (!$asSavepoint || !$this->transactionDepth)
{
parent::transactionStart($asSavepoint);
}
else
{
$savepoint = 'SP_' . $this->transactionDepth;
$this->setQuery('SAVEPOINT ' . $this->quoteName($savepoint));

if ($this->execute())
{
$this->transactionDepth++;
}
}
}
}

Ahora, tomando en consideracion este codigo, donde debería hacer los cambios?
  #9 (permalink)  
Antiguo 05/03/2015, 12:25
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: Error de Linea

Lo que tienes que cambiar ya te lo escribi antes. donde lo tienes que hacer es aqui:
Código PHP:
Ver original
  1. /**
  2. * Test to see if the MySQL connector is available.
  3. *
  4. * @return boolean True on success, false otherwise.
  5. *
  6. * @since 3.4
  7. */
  8. public static function isSupported()
  9. {
  10.   return in_array('mysql', PDO::getAvailableDrivers());
  11. }
Es una sola linea, así que no creo que tengas complicaciones
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.
  #10 (permalink)  
Antiguo 05/03/2015, 12:38
 
Fecha de Ingreso: marzo-2015
Mensajes: 6
Antigüedad: 9 años, 1 mes
Puntos: 0
Respuesta: Error de Linea

El problema persiste

ahora esta enviandome este error

Fatal error: Class 'PDO' not found in /home/dicte7zp/public_html/miportal/libraries/joomla/database/driver/pdomysql.php on line 102
  #11 (permalink)  
Antiguo 05/03/2015, 13:00
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: Error de Linea

http://www.inmotionhosting.com/suppo...-pdo-not-found
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.

Etiquetas: sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:08.